<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <title></title>
    <#include "../style.ftl" />
    <script type="text/javascript">
        $(document).ready(function () {
            $('.gwccheck').click(function(){
                var id = $(this).attr("data-id");
                if($(this).attr("class")=="gwccheck on"){
                    $(this).removeClass('on');
                    setDefaultAddress(id,'N');
                }else{
                    $(this).addClass('on');
                    setDefaultAddress(id,'Y');
                }
            })
        })
        function setDefaultAddress(id,defaultAddress){
            jQuery.post("${basePath}home/express/address/setDefault", {'addressId':id,'defaultAddress':defaultAddress},function(result){
                if(result.success){
                    location.href=location.href;
                }else {
                    alert(result.msg);
                }
            });
        }
    </script>
</head>
<body>
<div class="headerbox">
    <div class="header">
        <div class="headerL">
            <a onclick="javascript:history.back(-1)" class="goback"><img src="${staticPath}front/images/goback.png" /></a>
        </div>
        <div class="headerC">
            <p>管理收货地址</p>
        </div>
        <div class="headerR">
            <a href="${basePath}home/express/address/get?cartIds=${params.cartIds!}">添加</a>
        </div>
    </div>
</div>
<div class="clear"></div>

<#list memberAddressList as memberAddress>
<div class="kbox"></div>
<div class="addressbox">
    <div class="addressbox_1" onclick="chooseAddress('${memberAddress.id}')">
        <p class="p1" style="margin-top: 36px;">收货人：${memberAddress.realName!}<span>${memberAddress.mobile!}</span></p>
        <p class="p2">${memberAddress.provincename!}${memberAddress.cityname!}${memberAddress.countyname!}${memberAddress.address!}</p>
    </div>
    <div class="addressbox_2">
        <div class="ad1">
            <div class="ad1_1">
                <div <#if memberAddress.defaultAddress=='Y'>class="gwccheck on" <#else> class="gwccheck" </#if> data-id="${memberAddress.id!}"></div>
            </div>
            <div class="ad1_2">设为默认</div>
        </div>
        <div class="ad2">
            <div class="ad2_1"><img src="${staticPath}front/images/del.png" /></div>
            <div class="ad2_2" onclick="delAddress('${memberAddress.id}')">删除</div>
        </div>
        <div class="ad2 mr">
            <a href="${basePath}home/express/address/get?cartIds=${params.cartIds!}&skuId=${params.skuId!}&qty=${params.qty!}&addressId=${memberAddress.id!}">
                <div class="ad2_1"><img src="${staticPath}front/images/edit.png" /></div>
                <div class="ad2_2">
                    <a href="${basePath}home/express/address/get?cartIds=${params.cartIds!}&skuId=${params.skuId!}&qty=${params.qty!}&addressId=${memberAddress.id!}">编辑</a>
                </div>
            </a>
        </div>
    </div>
</div>
</#list>
</body>
<script>
    function delAddress(id){
        jQuery.post("${basePath}home/express/address/del", {'addressId':id},function(result){
            if(result.success){
                location.href=location.href;
            }else {
                alert(result.msg);
            }
        });
    }
    function chooseAddress(addressId){
        <#if params.cartIds??>
            location.href="${basePath}home/settle/cart?cartIds=${params.cartIds!}&addressId="+addressId;
        <#elseif params.skuId??>
            location.href="${basePath}home/settle/product?skuId=${params.skuId!}&qty=${params.qty!}&addressId="+addressId;
        </#if>
    }
</script>
</html>
